<template>
  <div class="app-container">
    <!-- 统计卡片 -->
    <el-row :gutter="20" class="stat-cards">
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card total-card">
          <div class="card-content">
            <div class="card-icon">
              <i class="el-icon-document"></i>
            </div>
            <div class="card-info">
              <div class="card-title">合同总数</div>
              <div class="card-value">{{ total }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card generated-card">
          <div class="card-content">
            <div class="card-icon">
              <i class="el-icon-edit-outline"></i>
            </div>
            <div class="card-info">
              <div class="card-title">已生成</div>
              <div class="card-value">{{ getStatusCount('GENERATED') }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card signed-card">
          <div class="card-content">
            <div class="card-icon">
              <i class="el-icon-check"></i>
            </div>
            <div class="card-info">
              <div class="card-title">已签署</div>
              <div class="card-value">{{ getStatusCount('SIGNED') }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card archived-card">
          <div class="card-content">
            <div class="card-icon">
              <i class="el-icon-folder"></i>
            </div>
            <div class="card-info">
              <div class="card-title">已归档</div>
              <div class="card-value">{{ getStatusCount('ARCHIVED') }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 搜索表单 -->
    <el-card shadow="hover" class="search-card">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="合同编号" prop="contractNo">
          <el-input
            v-model="queryParams.contractNo"
            placeholder="请输入合同编号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="合同标题" prop="contractTitle">
          <el-input
            v-model="queryParams.contractTitle"
            placeholder="请输入合同标题"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="甲方" prop="partyA">
          <el-input
            v-model="queryParams.partyA"
            placeholder="请输入甲方"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="乙方" prop="partyB">
          <el-input
            v-model="queryParams.partyB"
            placeholder="请输入乙方"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择合同状态" clearable size="small">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" class="toolbar"></right-toolbar>
    </el-card>

    <!-- 数据表格 -->
    <el-card shadow="hover" class="table-card">
      <div class="table-toolbar">
        <div class="left-buttons">
          <el-button type="primary" size="mini" icon="el-icon-upload2" @click="openUploadVerifyDialog">
            上传验证
          </el-button>
        </div>
      </div>
      
      <el-table
        v-loading="loading"
        :data="contractList"
        @selection-change="handleSelectionChange"
        stripe
        border
        highlight-current-row
        class="contract-table"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="合同编号" align="center" prop="contractNo" min-width="120" />
        <el-table-column label="合同标题" align="center" prop="contractTitle" min-width="180" :show-overflow-tooltip="true" />
        <el-table-column label="结构名称" align="center" prop="structName" min-width="150" :show-overflow-tooltip="true" />
        <el-table-column label="甲方" align="center" prop="partyA" min-width="150" :show-overflow-tooltip="true" />
        <el-table-column label="乙方" align="center" prop="partyB" min-width="150" :show-overflow-tooltip="true" />
        <el-table-column label="状态" align="center" prop="status" width="100">
          <template slot-scope="scope">
            <div class="status-with-chain">
              <el-tag :type="getStatusType(scope.row.status)" effect="plain">{{ getStatusText(scope.row.status) }}</el-tag>
              <el-tag 
                v-if="scope.row.chainStatus" 
                :type="getChainStatusType(scope.row.chainStatus)" 
                effect="plain" 
                size="mini"
                class="chain-tag">
                {{ getChainStatusText(scope.row.chainStatus) }}
              </el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="280">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-view"
              circle
              @click="handleView(scope.row)"
              title="查看详情"
            ></el-button>
            <el-button
              size="mini"
              type="success"
              icon="el-icon-download"
              circle
              @click="handleDownload(scope.row)"
              title="下载合同"
            ></el-button>
            <el-button
              size="mini"
              type="warning"
              icon="el-icon-upload"
              circle
              @click="handleReplace(scope.row)"
              title="替换合同"
            ></el-button>
            <el-button
              v-if="scope.row.chainStatus === 'CONFIRMED'"
              size="mini"
              type="info"
              icon="el-icon-document-checked"
              circle
              @click="openUploadVerifyDialog(scope.row)"
              title="区块链存证验证"
            ></el-button>
            <el-button
              size="mini"
              type="warning"
              icon="el-icon-edit"
              circle
              @click="handleEdit(scope.row)"
              title="编辑状态"
            ></el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              circle
              @click="handleDelete(scope.row)"
              title="删除合同"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        class="pagination"
      />
    </el-card>

    <!-- 合同详情对话框 -->
    <el-dialog title="合同详情" :visible.sync="viewOpen" width="700px" append-to-body custom-class="contract-detail-dialog">
      <div class="contract-header">
        <h2>{{ viewForm.contractTitle }}</h2>
        <el-tag :type="getStatusType(viewForm.status)" effect="dark">{{ getStatusText(viewForm.status) }}</el-tag>
      </div>

      <div class="contract-info">
        <div class="info-section">
          <h3>基本信息</h3>
          <div class="info-grid">
            <div class="info-item">
              <div class="info-label">合同编号</div>
              <div class="info-value">{{ viewForm.contractNo }}</div>
            </div>
            <div class="info-item">
              <div class="info-label">结构名称</div>
              <div class="info-value">{{ viewForm.structName }}</div>
            </div>
            <div class="info-item full-width">
              <div class="info-label">结构ID</div>
              <div class="info-value">{{ viewForm.structId }}</div>
            </div>
          </div>
        </div>

        <div class="info-section">
          <h3>签约方信息</h3>
          <div class="info-grid">
            <div class="info-item full-width">
              <div class="info-label">甲方</div>
              <div class="info-value">{{ viewForm.partyA }}</div>
            </div>
            <div class="info-item full-width">
              <div class="info-label">乙方</div>
              <div class="info-value">{{ viewForm.partyB }}</div>
            </div>
          </div>
        </div>

        <div class="info-section">
          <h3>文件信息</h3>
          <div class="info-grid">
            <div class="info-item full-width">
              <div class="info-label">文件路径</div>
              <div class="info-value file-path" @click="handleDownload(viewForm)">
                <i class="el-icon-document"></i> {{ viewForm.filePath || '无文件路径' }}
              </div>
            </div>
            <div class="info-item full-width">
              <div class="info-label">创建时间</div>
              <div class="info-value">{{ parseTime(viewForm.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</div>
            </div>
          </div>
        </div>

        <!-- 添加区块链信息部分 -->
        <div class="info-section" v-if="viewForm.chainStatus">
          <h3>区块链信息</h3>
          <div class="info-grid">
            <div class="info-item">
              <div class="info-label">上链状态</div>
              <div class="info-value">
                <el-tag :type="getChainStatusType(viewForm.chainStatus)">
                  {{ getChainStatusText(viewForm.chainStatus) }}
                </el-tag>
              </div>
            </div>
            <div class="info-item">
              <div class="info-label">上链时间</div>
              <div class="info-value">{{ parseTime(viewForm.chainTime, '{y}-{m}-{d} {h}:{i}:{s}') || '暂无' }}</div>
            </div>
            <div class="info-item full-width">
              <div class="info-label">交易哈希</div>
              <div class="info-value hash-value">{{ viewForm.txHash || '暂无' }}</div>
            </div>
            <div class="info-item full-width">
              <div class="info-label">存证编号</div>
              <div class="info-value">{{ viewForm.chainCertNo || '暂无' }}</div>
            </div>
            <div class="info-item full-width" v-if="viewForm.chainStatus === 'CONFIRMED'">
              <el-button type="primary" size="small" @click="openUploadVerifyDialog(viewForm)" :loading="verifying">验证合同完整性</el-button>
              <div class="verify-result" v-if="verifyResult !== null">
                <i :class="verifyResult ? 'el-icon-success success-icon' : 'el-icon-error error-icon'"></i>
                <span>{{ verifyResult ? '验证通过，合同未被篡改' : '验证失败，合同可能已被篡改' }}</span>
              </div>
            </div>
          </div>
        </div>
        <!-- 区块链信息部分结束 -->
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
        <el-button 
          v-if="viewForm.status === 'SIGNED' && (!viewForm.chainStatus || viewForm.chainStatus === 'FAILED')" 
          type="primary" 
          icon="el-icon-upload2" 
          @click="handleUploadToChain(viewForm)" 
          :loading="uploading">上传到区块链</el-button>
        <el-button type="primary" icon="el-icon-download" @click="handleDownload(viewForm)">下载合同</el-button>
      </div>
    </el-dialog>

    <!-- 合同状态编辑对话框 -->
    <el-dialog title="编辑合同状态" :visible.sync="editOpen" width="500px" append-to-body>
      <el-form ref="editForm" :model="editForm" :rules="editRules" label-width="100px">
        <el-form-item label="合同编号">
          <span class="edit-static-text">{{ editForm.contractNo }}</span>
        </el-form-item>
        <el-form-item label="合同标题">
          <span class="edit-static-text">{{ editForm.contractTitle }}</span>
        </el-form-item>
        <el-form-item label="当前状态">
          <el-tag :type="getStatusType(editForm.currentStatus)" effect="plain">
            {{ getStatusText(editForm.currentStatus) }}
          </el-tag>
        </el-form-item>
        <el-form-item label="更新状态" prop="status">
          <el-select v-model="editForm.status" placeholder="请选择合同状态" style="width: 100%">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editOpen = false">取 消</el-button>
        <el-button type="primary" @click="submitStatusEdit">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 上链进度对话框 -->
    <el-dialog title="上链进度" :visible.sync="uploadProgress.visible" width="600px" append-to-body custom-class="upload-progress-dialog">
      <div class="upload-progress">
        <div class="progress-header">
          <h3>{{ uploadProgress.contractTitle }}</h3>
          <el-tag size="small">{{ uploadProgress.contractNo }}</el-tag>
        </div>
        
        <div class="progress-steps">
          <div class="step" :class="{ active: uploadProgress.progress >= 20, completed: uploadProgress.progress >= 50 }">
            <div class="step-icon">
              <i class="el-icon-upload"></i>
            </div>
            <div class="step-label">准备数据</div>
          </div>
          <div class="step" :class="{ active: uploadProgress.progress >= 50, completed: uploadProgress.progress >= 90 }">
            <div class="step-icon">
              <i class="el-icon-connection"></i>
            </div>
            <div class="step-label">上链中</div>
          </div>
          <div class="step" :class="{ active: uploadProgress.progress === 100, completed: uploadProgress.status === 'success' }">
            <div class="step-icon">
              <i class="el-icon-check"></i>
            </div>
            <div class="step-label">确认</div>
          </div>
        </div>
        
        <div class="progress-bar-container">
          <div class="progress-bar">
            <div class="progress-fill" 
                 :style="{ width: uploadProgress.progress + '%' }"
                 :class="{ 
                   'success-bar': uploadProgress.status === 'success', 
                   'error-bar': uploadProgress.status === 'error',
                   'pending-bar': uploadProgress.status === 'pending' && uploadProgress.progress === 100
                 }">
            </div>
          </div>
          <div class="progress-percentage">{{ uploadProgress.progress }}%</div>
        </div>
        
        <div class="progress-message" :class="{ 
             'success-message': uploadProgress.status === 'success', 
             'error-message': uploadProgress.status === 'error',
             'pending-message': uploadProgress.status === 'pending' && uploadProgress.progress === 100 
           }">
          <i v-if="uploadProgress.status === 'success'" class="el-icon-success"></i>
          <i v-else-if="uploadProgress.status === 'error'" class="el-icon-error"></i>
          <i v-else-if="uploadProgress.status === 'pending' && uploadProgress.progress === 100" class="el-icon-warning-outline"></i>
          <i v-else class="el-icon-loading"></i>
          <span>{{ uploadProgress.message }}</span>
        </div>
        
        <div v-if="uploadProgress.txHash" class="transaction-hash">
          <div class="tx-label">交易 ID:</div>
          <div class="tx-value">{{ uploadProgress.txHash }}</div>
        </div>
        
        <div v-if="uploadProgress.status === 'pending' && uploadProgress.progress === 100" class="blockchain-info">
          <div class="info-title">蚂蚁链确认信息</div>
          <div class="info-content">
            <p>区块链交易通常需要一段时间才能被确认，特别是在网络繁忙时。</p>
            <p>您的交易已成功提交到蚂蚁链，但尚未获得足够的确认。</p>
            <p>您可以关闭此对话框，系统会在后台继续处理。您可以稍后在合同详情中查看最终状态。</p>
          </div>
        </div>
      </div>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="uploadProgress.visible = false">关闭</el-button>
        <el-button 
          v-if="uploadProgress.status === 'success' || uploadProgress.allowViewDetails" 
          type="primary" 
          @click="handleViewAfterUpload(uploadProgress.contractNo)">
          查看详情
        </el-button>
      </div>
    </el-dialog>

    <!-- 合同存证验证对话框 -->
    <el-dialog title="区块链存证验证" :visible.sync="verifyDialogVisible" width="850px" append-to-body custom-class="verify-dialog">
      <div v-if="verifying" class="verify-loading">
        <i class="el-icon-loading"></i>
        <p>正在从蚂蚁链获取存证信息并验证合同完整性...</p>
      </div>
      <div v-else-if="!verifyStarted" class="verify-upload-container">
        <div class="upload-header">
          <h3>上传合同文件进行验证</h3>
          <p>请上传您要验证的合同文件，系统将计算其哈希值并与区块链上存储的哈希值进行对比，以验证文件是否被篡改。</p>
        </div>
        
        <div class="upload-form">
          <el-form :model="uploadVerifyForm" ref="uploadVerifyForm" label-width="100px">
            <el-form-item label="合同编号" prop="contractNo" required>
              <el-input v-model="uploadVerifyForm.contractNo" placeholder="请输入要验证的合同编号" clearable :disabled="!!uploadVerifyForm.contractNo"></el-input>
            </el-form-item>
            <el-form-item label="合同文件" prop="file" required>
              <el-upload
                class="contract-file-uploader"
                action="#"
                :auto-upload="false"
                :on-change="handleVerifyFileChange"
                :limit="1"
                :file-list="uploadVerifyForm.fileList"
                drag>
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                <div slot="tip" class="el-upload__tip">请上传合同文件（PDF或Word文档）</div>
              </el-upload>
            </el-form-item>
          </el-form>
        </div>
        
        <div class="blockchain-info verify-info">
          <div class="info-title"><i class="el-icon-info"></i> 区块链存证说明</div>
          <div class="info-content">
            <p>区块链存证利用区块链不可篡改的特性，为合同文件提供了可信的防篡改验证机制。</p>
            <p>当您上传文件后，系统会计算文件的哈希值并与区块链上记录进行比对。</p>
            <p>如果两个哈希值一致，证明文件未被篡改；如果不一致，表示文件可能已被修改。</p>
          </div>
        </div>
      </div>
      <div v-else class="verify-flat-container">
        <!-- 标题和验证结果栏 -->
        <div class="verify-flat-header">
          <div class="flat-header-left">
            <span class="contract-title">{{ verifyData.contractTitle || uploadVerifyForm.contractNo }}</span>
            <el-tag size="mini" type="info">{{ verifyData.contractNo || uploadVerifyForm.contractNo }}</el-tag>
          </div>
          <div class="flat-header-right">
            <div class="verify-badge" :class="{ 'success': verifyResult === true, 'error': verifyResult === false }">
              <i :class="verifyResult === true ? 'el-icon-success' : 'el-icon-error'"></i>
              <span>{{ verifyResult === true ? '验证通过' : '验证失败' }}</span>
            </div>
          </div>
        </div>
        
        <!-- 3列布局 -->
        <el-row :gutter="15" class="verify-row">
          <!-- 验证结果说明 -->
          <el-col :span="8">
            <div class="verify-panel">
              <div class="panel-header">
                <i class="el-icon-document-checked"></i> 验证结果
              </div>
              <div class="panel-body">
                <div class="verify-result-text" :class="{ 'success-text': verifyResult === true, 'error-text': verifyResult === false }">
                  <p v-if="verifyResult === true">合同文件未被篡改，与区块链上记录的存证一致</p>
                  <p v-else-if="verifyResult === false">警告：合同文件可能已被篡改，与区块链上记录的存证不一致</p>
                </div>
              </div>
            </div>
          </el-col>
          
          <!-- 区块链信息 -->
          <el-col :span="8">
            <div class="verify-panel">
              <div class="panel-header">
                <i class="el-icon-connection"></i> 区块链信息
              </div>
              <div class="panel-body">
                <div class="info-item">
                  <span class="item-label">上链时间</span>
                  <span class="item-value">{{ parseTime(verifyData.chainTime, '{y}-{m}-{d}') }}</span>
                </div>
                <div class="info-item">
                  <span class="item-label">存证编号</span>
                  <span class="item-value">{{ verifyData.chainCertNo }}</span>
                </div>
                <div class="info-item">
                  <span class="item-label">交易ID</span>
                  <el-tooltip :content="verifyData.txHash" placement="top">
                    <span class="item-value tx-id">{{ verifyData.txHash.substring(0, 10) + '...' }}</span>
                  </el-tooltip>
                </div>
              </div>
            </div>
          </el-col>
          
          <!-- 哈希比对 -->
          <el-col :span="8">
            <div class="verify-panel">
              <div class="panel-header">
                <i class="el-icon-finished"></i> 哈希比对
              </div>
              <div class="panel-body">
                <div class="hash-comparison-mini" :class="{ 'success': verifyData.currentHash === verifyData.storedHash, 'error': verifyData.currentHash !== verifyData.storedHash }">
                  <i :class="verifyData.currentHash === verifyData.storedHash ? 'el-icon-check' : 'el-icon-close'"></i>
                  <span>{{ verifyData.currentHash === verifyData.storedHash ? '哈希值一致' : '哈希值不一致' }}</span>
                </div>
                <el-popover
                  placement="left"
                  width="400"
                  trigger="click">
                  <div class="hash-popup">
                    <div class="hash-item">
                      <div class="hash-label">当前文件哈希</div>
                      <div class="hash-value mono" :class="{ 'error-text': verifyData.currentHash !== verifyData.storedHash }">
                        {{ verifyData.currentHash }}
                      </div>
                    </div>
                    <div class="hash-item">
                      <div class="hash-label">区块链存证哈希</div>
                      <div class="hash-value mono">{{ verifyData.storedHash }}</div>
                    </div>
                  </div>
                  <el-button slot="reference" type="text" size="small">查看完整哈希</el-button>
                </el-popover>
              </div>
            </div>
          </el-col>
        </el-row>
        
        <!-- 简短说明 -->
        <div class="verify-flat-footer">
          <p>区块链存证通过哈希算法验证合同文件完整性，哈希值一致表示文件未被篡改，可确保合同真实性和不可篡改性。</p>
        </div>
      </div>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="verifyDialogVisible = false">关闭</el-button>
        <el-button v-if="!verifyStarted && !verifying" type="primary" @click="submitVerifyFile">开始验证</el-button>
        <el-button v-if="verifyStarted && !verifying" type="primary" @click="downloadVerificationReport">下载验证报告</el-button>
      </div>
    </el-dialog>

    <!-- 合同替换对话框 -->
    <el-dialog 
      title="替换合同" 
      :visible.sync="replaceDialogVisible" 
      width="580px" 
      append-to-body 
      custom-class="contract-replace-dialog"
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <div class="replace-dialog-content">
        <!-- 合同信息卡片 -->
        <div class="contract-card">
          <div class="contract-header">
            <i class="el-icon-document"></i>
            <span class="contract-title">合同信息</span>
          </div>
          <div class="contract-body">
            <div class="contract-item">
              <span class="item-label">合同编号</span>
              <span class="item-value">{{ replaceForm.contractNo }}</span>
            </div>
          </div>
        </div>

        <!-- 文件上传区域 -->
        <div class="upload-section">
          <el-upload
            class="file-uploader"
            action="#"
            :auto-upload="false"
            :on-change="handleReplaceFileChange"
            :limit="1"
            :file-list="replaceForm.fileList"
            drag>
            <div class="upload-area">
              <div class="upload-icon">
                <i class="el-icon-upload"></i>
              </div>
              <div class="upload-text">
                <p class="main-text">拖拽文件到此处或点击上传</p>
                <p class="sub-text">支持 PDF、Word 文档格式</p>
              </div>
            </div>
          </el-upload>
        </div>

        <!-- 上传提示 -->
        <div class="upload-tips">
          <div class="tip-item">
            <i class="el-icon-info"></i>
            <span>请确保上传的文件格式正确且内容完整</span>
          </div>
          <div class="tip-item">
            <i class="el-icon-warning"></i>
            <span>替换后的文件将覆盖原有文件，请谨慎操作</span>
          </div>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button 
          class="cancel-btn" 
          @click="replaceDialogVisible = false">
          取消
        </el-button>
        <el-button 
          class="confirm-btn" 
          type="primary" 
          @click="submitReplace" 
          :loading="replacing">
          确认替换
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listContract,
  getContract,
  delContract,
  downloadContract,
  updateContractStatus,
  uploadContractToChain,
  getContractChainStatus,
  verifyContractChainData,
  verifyContractByUpload,
  replaceContract
} from "@/api/contract/contract";

export default {
  name: "ContractManagement",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合同表格数据
      contractList: [],
      // 查看详情弹出层
      viewOpen: false,
      // 合同状态选项
      statusOptions: [
        { dictLabel: "已生成", dictValue: "GENERATED" },
        { dictLabel: "已签署", dictValue: "SIGNED" },
        { dictLabel: "已归档", dictValue: "ARCHIVED" }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractNo: null,
        contractTitle: null,
        partyA: null,
        partyB: null,
        status: null
      },
      // 查看表单详情
      viewForm: {},
      // 编辑弹出层
      editOpen: false,
      // 编辑表单
      editForm: {
        id: null,
        contractNo: null,
        contractTitle: null,
        currentStatus: null,
        status: null
      },
      // 编辑表单验证
      editRules: {
        status: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ]
      },
      // 区块链相关
      uploading: false,
      verifying: false,
      verifyResult: null,
      verifyStarted: false,
      uploadVerifyForm: {
        contractNo: '',
        fileList: [],
        file: null
      },
      blockchainConfig: {
        provider: 'ANT_CHAIN',
        networkName: '蚂蚁链',
        description: '蚂蚁集团旗下企业级区块链平台'
      },
      // 链上状态轮询相关
      chainStatusTimer: null,
      // 上链进度相关
      uploadProgress: {
        visible: false,
        contractNo: null,
        contractTitle: null,
        status: 'pending', // pending, uploading, success, error
        message: '',
        txHash: null,
        progress: 0,
        pollCount: 0,
        pollTimer: null,
        allowViewDetails: false
      },
      // 合同存证验证相关
      verifyDialogVisible: false,
      verifyData: {
        contractNo: '',
        contractTitle: '',
        chainStatus: '',
        txHash: '',
        chainTime: '',
        chainCertNo: '',
        currentHash: '',
        storedHash: ''
      },
      replaceDialogVisible: false,
      replaceForm: {
        contractNo: '',
        fileList: [],
        file: null
      },
      replacing: false
    };
  },
  created() {
    this.getList();
    // 启动链上状态轮询
    this.startChainStatusPolling();
  },
  beforeDestroy() {
    // 组件销毁前清除定时器
    this.clearChainStatusPolling();
  },
  methods: {
    /** 查询合同列表并加载链上状态 */
    getList() {
      this.loading = true;
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
        
        // 获取已签署合同的链上状态
        this.fetchChainStatusForContracts();
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 查看合同详情按钮操作 */
    handleView(row) {
      getContract(row.id).then(response => {
        this.viewForm = response.data;
        this.viewOpen = true;
        this.verifyResult = null; // 重置验证结果
        
        // 如果合同已签署，尝试获取链上状态
        if (row.status === 'SIGNED' || row.status === 'CHAINED') {
          this.getContractChainStatus(row.contractNo);
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除合同编号为"' + row.contractNo + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.loading = true;
        return delContract(row.id);
      }).then(() => {
        this.getList();
        this.$message({
          type: 'success',
          message: '删除成功',
          duration: 1500
        });
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 下载合同操作 */
    handleDownload(row) {
      this.loading = true;
      downloadContract(row.contractNo).then(response => {
        this.downloadFile(response, row.contractNo);
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 下载文件处理 */
    downloadFile(response, fileName) {
      const blob = new Blob([response]);
      const extension = this.getFileExtension(response.type);
      const downloadFileName = `${fileName}.${extension}`;

      if ("download" in document.createElement("a")) {
        const link = document.createElement("a");
        link.download = downloadFileName;
        link.style.display = "none";
        link.href = URL.createObjectURL(blob);
        document.body.appendChild(link);
        link.click();
        URL.revokeObjectURL(link.href);
        document.body.removeChild(link);

        this.$message({
          type: 'success',
          message: '下载成功',
          duration: 1500
        });
      } else {
        navigator.msSaveBlob(blob, downloadFileName);
      }
    },
    /** 获取文件扩展名 */
    getFileExtension(contentType) {
      if (contentType === "application/pdf") {
        return "pdf";
      } else if (contentType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
        return "docx";
      } else {
        return "docx"; // 默认返回docx
      }
    },
    /** 获取状态显示文本 */
    getStatusText(status) {
      const statusMap = {
        'GENERATED': '已生成',
        'SIGNED': '已签署',
        'ARCHIVED': '已归档',
        'CHAINED': '已上链'
      };
      return statusMap[status] || status;
    },
    /** 获取状态显示类型 */
    getStatusType(status) {
      const statusMap = {
        'GENERATED': 'info',
        'SIGNED': 'success',
        'ARCHIVED': 'warning',
        'CHAINED': 'primary'
      };
      return statusMap[status] || '';
    },
    /** 获取特定状态的合同数量 */
    getStatusCount(status) {
      return this.contractList.filter(item => item.status === status).length;
    },
    /** 编辑按钮操作 */
    handleEdit(row) {
      this.editForm = {
        id: row.id,
        contractNo: row.contractNo,
        contractTitle: row.contractTitle,
        currentStatus: row.status,
        status: row.status
      };
      this.editOpen = true;
      this.$nextTick(() => {
        this.$refs["editForm"].clearValidate();
      });
    },
    /** 提交状态编辑 */
    submitStatusEdit() {
      this.$refs["editForm"].validate(valid => {
        if (valid) {
          // 如果状态没有变化，直接关闭对话框
          if (this.editForm.currentStatus === this.editForm.status) {
            this.$message({
              message: "状态未发生变化",
              type: "info"
            });
            this.editOpen = false;
            return;
          }

          // 验证状态变更流程合法性
          if (this.editForm.currentStatus === 'SIGNED' && this.editForm.status === 'GENERATED') {
            this.$message({
              message: "已签署的合同不能退回到已生成状态",
              type: "warning"
            });
            return;
          }

          // 验证状态变更流程合法性
          if (this.editForm.currentStatus === 'ARCHIVED' && (this.editForm.status === 'GENERATED' || this.editForm.status === 'SIGNED')) {
            this.$message({
              message: "已归档的合同不能退回到之前的状态",
              type: "warning"
            });
            return;
          }

          this.loading = true;
          
          // 特殊处理：当状态变更为"已签署"时，需要计算哈希值并上链
          const isSignedStatus = this.editForm.status === "SIGNED";
          const currentRow = {
            id: this.editForm.id,
            contractNo: this.editForm.contractNo,
            contractTitle: this.editForm.contractTitle
          };
          
          // 调用更新状态API
          updateContractStatus({
            id: this.editForm.id,
            status: this.editForm.status
          }).then(() => {
            this.editOpen = false;
            this.loading = false;
            
            // 如果状态是"已签署"，自动将合同上链，使用异步方式
            if (isSignedStatus) {
              this.$message({
                type: "success",
                message: `状态已更新为已签署，即将开始上链过程`,
                duration: 2000
              });
              
              // 关闭当前对话框并延迟一段时间后显示上链进度
              setTimeout(() => {
                this.handleUploadToChain(currentRow);
              }, 1000);
            } else {
              this.$message({
                type: "success",
                message: "状态更新成功"
              });
            }
            
            // 刷新列表
            this.getList();
          }).catch(error => {
            this.loading = false;
            this.$message.error("状态更新失败: " + (error.message || "未知错误"));
          });
        }
      });
    },
    /** 获取链上状态文本 */
    getChainStatusText(status) {
      const statusMap = {
        'PENDING': '上链中',
        'CONFIRMED': '已上链',
        'FAILED': '上链失败'
      };
      return statusMap[status] || status;
    },
    
    /** 获取链上状态类型 */
    getChainStatusType(status) {
      const statusMap = {
        'PENDING': 'warning',
        'CONFIRMED': 'success',
        'FAILED': 'danger'
      };
      return statusMap[status] || 'info';
    },
    
    /** 上传合同到区块链 */
    handleUploadToChain(row) {
      this.$confirm(`是否确认将合同"${row.contractTitle}"上传至${this.blockchainConfig.networkName}进行存证?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info"
      }).then(() => {
        // 初始化上传进度对话框
        this.initUploadProgress(row);
        
        // 显示上传进度对话框
        this.uploadProgress.visible = true;
        this.uploadProgress.message = `正在计算合同哈希...`;
        this.updateProgressBar(20);
        
        // 异步上传到区块链
        setTimeout(() => {
          uploadContractToChain(row.contractNo)
            .then(response => {
        if (response.code === 200) {
                this.uploadProgress.txHash = response.data.txHash;
                this.uploadProgress.message = `合同哈希已提交至${this.blockchainConfig.networkName}，交易ID: ${response.data.txHash}`;
                this.updateProgressBar(50);
                
                // 模拟上链进度，7秒后显示成功
                let progress = 50;
                const progressInterval = setInterval(() => {
                  progress += 8;
                  if (progress >= 100) {
                    clearInterval(progressInterval);
                    this.uploadProgress.status = 'success';
                    this.uploadProgress.message = `合同已成功上链并得到确认，交易ID: ${response.data.txHash}`;
                    this.updateProgressBar(100, 'success');
                    
                    // 播放成功提示音效
                    try {
                      const audio = new Audio('/success.mp3');
                      audio.play().catch(() => {});
                    } catch (e) {
                      // 忽略播放音效失败的错误
                    }
                    
                    // 显示成功通知
                    this.$notify({
                      title: '上链成功',
                      message: `合同"${row.contractTitle}"已成功上传至${this.blockchainConfig.networkName}`,
                      type: 'success',
                      duration: 4000
          });
                    
                    // 刷新列表
                    this.getList();
                    
                    // 如果当前正在查看该合同详情，更新详情中的链上状态
                    if (this.viewOpen && this.viewForm.contractNo === row.contractNo) {
                      this.refreshContractDetail(this.viewForm.id);
                    }
        } else {
                    this.updateProgressBar(progress);
                  }
                }, 1000); // 每秒更新一次进度，7秒完成
                
              } else {
                this.uploadProgress.status = 'error';
                this.uploadProgress.message = `上链失败：${response.msg || "未知错误"}`;
                this.updateProgressBar(100, 'error');
        }
            })
            .catch(error => {
          console.error("上链失败:", error);
              this.uploadProgress.status = 'error';
              this.uploadProgress.message = `上链失败：${error.message || "未知错误"}`;
              this.updateProgressBar(100, 'error');
            });
        }, 500);
      }).catch(() => {
        // 用户取消上链操作
      });
    },
    
    /** 初始化上传进度对话框 */
    initUploadProgress(row) {
      // 清除上一次的轮询
      if (this.uploadProgress.pollTimer) {
        clearInterval(this.uploadProgress.pollTimer);
        this.uploadProgress.pollTimer = null;
      }
      
      // 初始化上传进度数据
      this.uploadProgress = {
        visible: false,
        contractNo: row.contractNo,
        contractTitle: row.contractTitle,
        status: 'pending',
        message: '',
        txHash: null,
        progress: 0,
        pollCount: 0,
        pollTimer: null,
        allowViewDetails: false
      };
    },
    
    /** 更新进度条 */
    updateProgressBar(progress, status = null) {
      this.uploadProgress.progress = progress;
      if (status) {
        this.uploadProgress.status = status;
      }
    },
    
    /** 轮询交易状态 */
    pollTransactionStatus(contractNo, txHash) {
      // 设置轮询计时器，每5秒查询一次
      this.uploadProgress.pollTimer = setInterval(() => {
        // 增加轮询计数
        this.uploadProgress.pollCount++;
        
        // 更新轮询消息 (每30次轮询显示新的消息以指示仍在进行中)
        if (this.uploadProgress.pollCount % 30 === 0) {
          this.uploadProgress.message = `区块链交易正在处理中，蚂蚁链确认可能需要一些时间，请耐心等待... (${this.uploadProgress.pollCount})`;
        } else {
          this.uploadProgress.message = `正在查询交易状态，请稍候... (${this.uploadProgress.pollCount})`;
        }
        
        // 限制最大轮询次数（15分钟，5秒一次，共180次）
        if (this.uploadProgress.pollCount > 180) {
          clearInterval(this.uploadProgress.pollTimer);
          this.uploadProgress.status = 'pending';
          this.uploadProgress.message = `等待区块链确认时间较长，交易已提交但尚未确认。您可以稍后在合同详情中查看最终状态，交易ID: ${txHash}`;
          this.updateProgressBar(100, 'pending');
          
          // 添加查看详情按钮
          this.$set(this.uploadProgress, 'allowViewDetails', true);
          
          // 轮询超时，但不一定是失败，所以刷新一下列表
          this.getList();
          return;
        }
        
        // 更新进度条（50-95之间波动，预留最后5%给最终确认）
        const progressRate = Math.min(0.25, 45 / 180); // 动态计算每次增加的进度比例
        const newProgress = 50 + Math.min(this.uploadProgress.pollCount * progressRate, 45);
        this.updateProgressBar(newProgress);
        
        // 调用API查询交易状态
        getContractChainStatus(contractNo)
          .then(response => {
            if (response.code === 200 && response.data) {
              // 如果交易已确认，停止轮询
              if (response.data.chainStatus === 'CONFIRMED') {
                clearInterval(this.uploadProgress.pollTimer);
                this.uploadProgress.status = 'success';
                this.uploadProgress.message = `合同已成功上链并得到确认，交易ID: ${txHash}`;
                this.updateProgressBar(100, 'success');
                
                // 刷新列表
                this.getList();
                
                // 如果当前正在查看该合同详情，更新详情中的链上状态
                if (this.viewOpen && this.viewForm.contractNo === contractNo) {
                  this.refreshContractDetail(this.viewForm.id);
                }
              }
              // 如果失败，停止轮询
              else if (response.data.chainStatus === 'FAILED') {
                clearInterval(this.uploadProgress.pollTimer);
                this.uploadProgress.status = 'error';
                this.uploadProgress.message = `上链失败，请稍后重试，交易ID: ${txHash}`;
                this.updateProgressBar(100, 'error');
              }
              // 如果是LOCAL_ONLY状态，可能是使用了模拟模式，但我们已经去掉了这个
              else if (response.data.chainStatus === 'LOCAL_ONLY') {
                clearInterval(this.uploadProgress.pollTimer);
                this.uploadProgress.status = 'pending';
                this.uploadProgress.message = `交易已记录但尚未提交到蚂蚁链，请联系管理员检查系统配置，交易ID: ${txHash}`;
                this.updateProgressBar(100, 'pending');
              }
              // 如果是PENDING状态，继续轮询
              else if (response.data.chainStatus === 'PENDING') {
                // 继续轮询，但每30次给一个提示
                if (this.uploadProgress.pollCount % 30 === 0) {
                  this.$message({
                    message: `合同已提交至蚂蚁链，正在等待确认(${this.uploadProgress.pollCount/12}分钟)`,
                    type: "info",
                    duration: 3000
                  });
                }
              }
            }
          })
          .catch(() => {
            // 查询失败不中断轮询，继续等待下一次查询
          });
      }, 5000); // 每5秒查询一次
    },
    
    /** 验证合同完整性 */
    handleVerifyContract(row) {
      this.verifying = true;
      this.verifyResult = null;
      
      this.$message({
        type: "info",
        message: `正在从${this.blockchainConfig.networkName}获取存证信息并验证合同完整性...`,
        duration: 2000
      });
      
      verifyContractChainData(row.contractNo)
        .then(response => {
          if (response.code === 200) {
            this.verifyResult = response.data.verified;
            this.$message({
              type: this.verifyResult ? "success" : "error",
              message: this.verifyResult 
                ? `验证通过，合同未被篡改，与${this.blockchainConfig.networkName}上的存证一致` 
                : `验证失败，合同可能已被篡改，与${this.blockchainConfig.networkName}上的存证不一致`,
              duration: 3000
            });
          } else {
            this.$message.error(response.msg || "验证失败");
          }
        })
        .catch(error => {
          console.error("验证失败:", error);
          this.$message.error("验证失败: " + (error.message || "未知错误"));
        })
        .finally(() => {
          this.verifying = false;
        });
    },
    
    /** 刷新合同详情 */
    refreshContractDetail(id) {
      getContract(id).then(response => {
        this.viewForm = response.data;
        
        // 如果合同已上链但详情中没有链上状态，尝试获取链上状态
        if ((this.viewForm.status === 'SIGNED' || this.viewForm.status === 'CHAINED') && 
            !this.viewForm.chainStatus) {
          this.getContractChainStatus(this.viewForm.contractNo);
        }
      });
    },
    
    /** 获取合同链上状态 */
    getContractChainStatus(contractNo) {
      getContractChainStatus(contractNo)
        .then(response => {
          if (response.code === 200 && response.data) {
            // 更新视图中的链上状态信息
            this.viewForm.chainStatus = response.data.chainStatus;
            this.viewForm.txHash = response.data.txHash;
            this.viewForm.chainTime = response.data.chainTime;
            this.viewForm.chainCertNo = response.data.chainCertNo;
          }
        })
        .catch(error => {
          console.error("获取链上状态失败:", error);
        });
    },
    
    /** 获取已签署合同的链上状态 */
    fetchChainStatusForContracts() {
      // 查找所有已签署的合同
      const signedContracts = this.contractList.filter(contract => 
        contract.status === 'SIGNED' || contract.status === 'CHAINED');
      
      // 为每个已签署的合同获取链上状态
      signedContracts.forEach(contract => {
        getContractChainStatus(contract.contractNo)
          .then(response => {
            if (response.code === 200 && response.data) {
              // 更新列表中的合同链上状态
              const index = this.contractList.findIndex(item => item.contractNo === contract.contractNo);
              if (index !== -1) {
                this.$set(this.contractList[index], 'chainStatus', response.data.chainStatus);
                this.$set(this.contractList[index], 'txHash', response.data.txHash);
                this.$set(this.contractList[index], 'chainTime', response.data.chainTime);
                this.$set(this.contractList[index], 'chainCertNo', response.data.chainCertNo);
              }
            }
          })
          .catch(error => {
            console.error(`获取合同 ${contract.contractNo} 链上状态失败:`, error);
          });
      });
    },
    
    /** 启动链上状态轮询 */
    startChainStatusPolling() {
      // 每60秒刷新一次链上状态
      this.chainStatusTimer = setInterval(() => {
        if (this.contractList && this.contractList.length > 0) {
          this.fetchChainStatusForContracts();
        }
      }, 60000); // 60秒
    },
    
    /** 清除链上状态轮询 */
    clearChainStatusPolling() {
      if (this.chainStatusTimer) {
        clearInterval(this.chainStatusTimer);
        this.chainStatusTimer = null;
      }
    },

    /** 上链成功后查看合同详情 */
    handleViewAfterUpload(contractNo) {
      // 先关闭上传进度对话框
      this.uploadProgress.visible = false;
      
      // 查找对应的合同记录
      const contract = this.contractList.find(item => item.contractNo === contractNo);
      if (contract) {
        this.handleView(contract);
      } else {
        // 如果在当前列表中找不到，可能是因为过滤条件，直接通过API获取
        this.getContractByContractNo(contractNo);
      }
    },
    
    /** 通过合同编号获取合同详情 */
    getContractByContractNo(contractNo) {
      this.loading = true;
      // 构造查询条件
      const query = {
        contractNo: contractNo,
        pageNum: 1,
        pageSize: 10
      };
      
      listContract(query).then(response => {
        if (response.rows && response.rows.length > 0) {
          // 找到合同，查看详情
          this.handleView(response.rows[0]);
        } else {
          this.$message.error("未找到对应的合同记录");
        }
        this.loading = false;
      }).catch(() => {
        this.loading = false;
        this.$message.error("获取合同详情失败");
      });
    },

    /** 打开合同存证验证对话框 */
    openUploadVerifyDialog(row = null) {
      // 重置验证表单和状态
      this.uploadVerifyForm = {
        contractNo: row ? row.contractNo : '',
        fileList: [],
        file: null
      };
      this.verifyStarted = false;
      this.verifyResult = null;
      this.verifyData = {
        contractNo: row ? row.contractNo : '',
        contractTitle: row ? row.contractTitle : '',
        chainStatus: row ? row.chainStatus : '',
        txHash: row ? row.txHash : '',
        chainTime: row ? row.chainTime : '',
        chainCertNo: row ? row.chainCertNo : '',
        currentHash: '',
        storedHash: ''
      };
      
      // 显示验证对话框
      this.verifyDialogVisible = true;
    },
    
    /** 处理验证文件上传 */
    handleVerifyFileChange(file) {
      // 更新上传文件列表
      this.uploadVerifyForm.fileList = [file];
      this.uploadVerifyForm.file = file.raw;
    },
    
    /** 提交文件验证 */
    submitVerifyFile() {
      // 验证表单
      if (!this.uploadVerifyForm.contractNo) {
        this.$message.error('请输入合同编号');
        return;
      }
      
      if (!this.uploadVerifyForm.file) {
        this.$message.error('请选择合同文件');
        return;
      }
      
      // 准备表单数据
      const formData = new FormData();
      formData.append('contractNo', this.uploadVerifyForm.contractNo);
      formData.append('file', this.uploadVerifyForm.file);
      
      // 开始验证
      this.verifying = true;
      this.verifyResult = null;
      
      // 调用API进行验证
      verifyContractByUpload(formData)
        .then(response => {
          if (response.code === 200) {
            // 更新验证状态
            this.verifyStarted = true;
            this.verifyResult = response.data.verified;
            
            // 更新验证数据
            this.verifyData = {
              contractNo: this.uploadVerifyForm.contractNo,
              contractTitle: response.data.contractTitle || this.uploadVerifyForm.contractNo,
              txHash: response.data.txHash,
              chainTime: response.data.chainTime,
              chainCertNo: response.data.chainCertNo,
              currentHash: response.data.currentHash,
              storedHash: response.data.storedHash
            };
            
            // 显示通知
            this.$notify({
              title: this.verifyResult ? '验证成功' : '验证失败',
              message: this.verifyResult 
                ? '合同文件未被篡改，与蚂蚁链上的存证一致' 
                : '警告：合同文件可能已被篡改，与蚂蚁链上的存证不一致',
              type: this.verifyResult ? 'success' : 'error',
              duration: 5000
            });
          } else {
            this.$message.error(response.msg || "验证失败");
            this.verifyResult = false;
          }
        })
        .catch(error => {
          console.error("验证失败:", error);
          this.$message.error("验证失败: " + (error.message || "未知错误"));
          this.verifyResult = false;
        })
        .finally(() => {
          this.verifying = false;
        });
    },
    
    /** 下载验证报告 */
    downloadVerificationReport() {
      // 创建验证报告内容
      const reportTime = this.parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}');
      const verificationStatus = this.verifyResult ? '验证通过' : '验证失败';
      const hashesMatch = this.verifyData.currentHash === this.verifyData.storedHash;
      
      // 创建HTML格式的报告，而不是纯文本
      const reportContent = `
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>区块链存证验证报告</title>
  <style>
    body {
      font-family: 'Microsoft YaHei', Arial, sans-serif;
      background-color: #f5f7fa;
      color: #303133;
      margin: 0;
      padding: 20px;
    }
    .report-container {
      max-width: 800px;
      margin: 0 auto;
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      padding: 30px;
    }
    .report-header {
      text-align: center;
      padding-bottom: 20px;
      border-bottom: 1px solid #ebeef5;
      margin-bottom: 30px;
    }
    .report-title {
      font-size: 24px;
      font-weight: bold;
      color: #409EFF;
      margin-bottom: 10px;
    }
    .report-subtitle {
      font-size: 16px;
      color: #909399;
    }
    .report-logo {
      width: 100px;
      height: 100px;
      margin: 0 auto 20px;
      display: block;
      background-color: #409EFF;
      border-radius: 50%;
      position: relative;
    }
    .report-logo::after {
      content: '√';
      font-size: 60px;
      color: white;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    .report-section {
      margin-bottom: 30px;
    }
    .section-title {
      font-size: 18px;
      color: #409EFF;
      padding-bottom: 10px;
      border-bottom: 1px solid #ebeef5;
      margin-bottom: 15px;
    }
    .info-row {
      display: flex;
      margin-bottom: 15px;
    }
    .info-label {
      width: 150px;
      font-weight: bold;
      color: #606266;
    }
    .info-value {
      flex: 1;
      word-break: break-all;
    }
    .hash-value {
      font-family: monospace;
      background-color: #f5f7fa;
      padding: 10px;
      border-radius: 4px;
      font-size: 14px;
      word-break: break-all;
    }
    .hash-comparison {
      margin-top: 15px;
      padding: 10px;
      border-radius: 4px;
      font-weight: bold;
      text-align: center;
    }
    .hash-match {
      background-color: #f0f9eb;
      color: #67C23A;
    }
    .hash-mismatch {
      background-color: #fef0f0;
      color: #F56C6C;
    }
    .verification-result {
      padding: 15px;
      border-radius: 4px;
      margin-bottom: 20px;
      display: flex;
      align-items: center;
    }
    .success {
      background-color: #f0f9eb;
      border: 1px solid #e1f3d8;
      color: #67C23A;
    }
    .fail {
      background-color: #fef0f0;
      border: 1px solid #fde2e2;
      color: #F56C6C;
    }
    .result-icon {
      font-size: 24px;
      margin-right: 10px;
    }
    .result-message {
      font-weight: bold;
      margin-bottom: 5px;
    }
    .result-detail {
      font-size: 14px;
    }
    .footer {
      text-align: center;
      margin-top: 30px;
      color: #909399;
      font-size: 14px;
    }
    .qr-placeholder {
      width: 150px;
      height: 150px;
      background-color: #f5f7fa;
      margin: 0 auto;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #909399;
      font-size: 12px;
      text-align: center;
    }
  </style>
</head>
<body>
  <div class="report-container">
    <div class="report-header">
      <div class="report-logo"></div>
      <div class="report-title">区块链存证验证报告</div>
      <div class="report-subtitle">生成时间: ${reportTime}</div>
    </div>
    
    <div class="verification-result ${this.verifyResult ? 'success' : 'fail'}">
      <div class="result-icon">${this.verifyResult ? '✓' : '✗'}</div>
      <div>
        <div class="result-message">${this.verifyResult ? '验证通过' : '验证失败'}</div>
        <div class="result-detail">
          ${this.verifyResult 
            ? '合同文件未被篡改，与区块链上记录的存证一致' 
            : '警告：合同文件可能已被篡改，与区块链上记录的存证不一致'}
        </div>
      </div>
    </div>
    
    <div class="report-section">
      <div class="section-title">合同信息</div>
      <div class="info-row">
        <div class="info-label">合同编号</div>
        <div class="info-value">${this.verifyData.contractNo}</div>
      </div>
      <div class="info-row">
        <div class="info-label">合同标题</div>
        <div class="info-value">${this.verifyData.contractTitle}</div>
      </div>
      <div class="info-row">
        <div class="info-label">验证结果</div>
        <div class="info-value">${verificationStatus}</div>
      </div>
    </div>
    
    <div class="report-section">
      <div class="section-title">区块链信息</div>
      <div class="info-row">
        <div class="info-label">区块链网络</div>
        <div class="info-value">蚂蚁链</div>
      </div>
      <div class="info-row">
        <div class="info-label">交易ID</div>
        <div class="info-value">${this.verifyData.txHash}</div>
      </div>
      <div class="info-row">
        <div class="info-label">上链时间</div>
        <div class="info-value">${this.parseTime(this.verifyData.chainTime, '{y}-{m}-{d} {h}:{i}:{s}')}</div>
      </div>
      <div class="info-row">
        <div class="info-label">存证编号</div>
        <div class="info-value">${this.verifyData.chainCertNo}</div>
      </div>
    </div>
    
    <div class="report-section">
      <div class="section-title">哈希信息</div>
      <div class="info-row">
        <div class="info-label">当前文件哈希</div>
        <div class="info-value">
          <div class="hash-value">${this.verifyData.currentHash}</div>
        </div>
      </div>
      <div class="info-row">
        <div class="info-label">区块链存证哈希</div>
        <div class="info-value">
          <div class="hash-value">${this.verifyData.storedHash}</div>
        </div>
      </div>
      <div class="${hashesMatch ? 'hash-match' : 'hash-mismatch'} hash-comparison">
        哈希比对结果: ${hashesMatch ? '一致' : '不一致'}
      </div>
    </div>
    
    <div class="report-section">
      <div class="section-title">验证说明</div>
      <p>
        区块链存证利用区块链不可篡改的特性，为合同文件提供了可信的防篡改验证机制。
        当合同上链后，系统会计算合同文件的哈希值并存储在蚂蚁链上，验证过程会重新计算当前文件的哈希值，
        并与链上记录进行比对。
      </p>
      <p>
        ${this.verifyResult 
          ? '验证通过，证明合同文件未被篡改，与区块链上记录的存证一致。' 
          : '验证失败，合同文件可能已被篡改，与区块链上记录的存证不一致。'}
      </p>
    </div>
    
    <div class="footer">
      <p>本报告由DIMS-HSRC系统自动生成，可作为合同完整性的电子证明</p>
      <p>报告编号: DIMS-${this.parseTime(new Date(), '{y}{m}{d}{h}{i}{s}')}-${this.verifyData.contractNo}</p>
    </div>
  </div>
</body>
</html>
      `;
      
      // 创建下载链接
      const blob = new Blob([reportContent], { type: 'text/html' });
      const link = document.createElement('a');
      link.href = URL.createObjectURL(blob);
      link.download = `验证报告_${this.verifyData.contractNo}_${this.parseTime(new Date(), '{y}{m}{d}{h}{i}{s}')}.html`;
      link.click();
      URL.revokeObjectURL(link.href);
    },
    
    /** 处理合同替换 */
    handleReplace(row) {
      this.replaceForm = {
        contractNo: row.contractNo,
        fileList: [],
        file: null
      };
      this.replaceDialogVisible = true;
    },
    
    /** 处理替换文件上传 */
    handleReplaceFileChange(file) {
      this.replaceForm.fileList = [file];
      this.replaceForm.file = file.raw;
    },
    
    /** 提交合同替换 */
    submitReplace() {
      if (!this.replaceForm.file) {
        this.$message.error('请选择要上传的合同文件');
        return;
      }
      
      const formData = new FormData();
      formData.append('contractNo', this.replaceForm.contractNo);
      formData.append('file', this.replaceForm.file);
      
      this.replacing = true;
      
      // 调用替换合同API
      replaceContract(formData)
        .then(response => {
          if (response.code === 200) {
            this.$message.success('合同替换成功');
            this.replaceDialogVisible = false;
            this.getList();
          } else {
            this.$message.error(response.msg || '合同替换失败');
          }
        })
        .catch(error => {
          console.error('合同替换失败:', error);
          this.$message.error('合同替换失败: ' + (error.message || '未知错误'));
        })
        .finally(() => {
          this.replacing = false;
        });
    }
  }
};
</script>

<style scoped>
/* 整体容器样式 */
.app-container {
  padding: 20px;
  background-color: #f5f7fa;
}

/* 统计卡片样式 */
.stat-cards {
  margin-bottom: 20px;
}

.stat-card {
  border-radius: 8px;
  transition: all 0.3s;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}

.card-content {
  display: flex;
  align-items: center;
}

.card-icon {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  border-radius: 50%;
  margin-right: 15px;
}

.card-info {
  flex: 1;
}

.card-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 5px;
}

.card-value {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
}

.total-card .card-icon {
  background-color: #e1f3ff;
  color: #409EFF;
}

.generated-card .card-icon {
  background-color: #e1ecff;
  color: #3a8ee6;
}

.signed-card .card-icon {
  background-color: #e1f5eb;
  color: #67C23A;
}

.archived-card .card-icon {
  background-color: #fdf5e6;
  color: #E6A23C;
}

/* 搜索卡片样式 */
.search-card {
  margin-bottom: 20px;
  border-radius: 8px;
}

.toolbar {
  margin-top: 15px;
}

/* 表格卡片样式 */
.table-card {
  border-radius: 8px;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.left-buttons {
  display: flex;
  gap: 10px;
}

.contract-table {
  margin-top: 10px;
}

.pagination {
  margin-top: 20px;
  text-align: right;
}

/* 标签样式 */
.el-tag {
  padding: 0 12px;
  height: 28px;
  line-height: 26px;
}

/* 操作按钮样式 */
.action-button {
  margin-right: 8px;
  border-radius: 4px;
}

.action-dropdown {
  padding: 7px;
}

/* 合同详情对话框样式 */
.contract-detail-dialog .el-dialog__body {
  padding: 0 20px;
}

.contract-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  margin-bottom: 20px;
  border-bottom: 1px solid #ebeef5;
}

.contract-header h2 {
  margin: 0;
  font-size: 18px;
  color: #303133;
}

.contract-info {
  padding-bottom: 20px;
}

.info-section {
  margin-bottom: 25px;
}

.info-section h3 {
  margin: 0 0 15px 0;
  font-size: 16px;
  color: #409EFF;
  font-weight: 500;
  position: relative;
  padding-left: 12px;
}

.info-section h3::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 16px;
  background-color: #409EFF;
  border-radius: 2px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.info-item {
  display: flex;
  flex-direction: column;
}

.info-item.full-width {
  grid-column: span 2;
}

.info-label {
  font-size: 13px;
  color: #909399;
  margin-bottom: 5px;
}

.info-value {
  color: #303133;
  word-break: break-all;
  line-height: 1.4;
}

.file-path {
  color: #409EFF;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.file-path i {
  margin-right: 5px;
}

.file-path:hover {
  text-decoration: underline;
}

/* 全局样式调整 */
.mb8 {
  margin-bottom: 8px;
}

/* 编辑对话框样式 */
.edit-static-text {
  color: #606266;
  font-size: 14px;
}

/* 添加一些额外的样式来美化编辑表单 */
.el-form-item {
  margin-bottom: 22px;
}

.el-textarea__inner {
  font-family: inherit;
}

.el-select {
  width: 100%;
}

/* 新增区块链信息相关样式 */
.hash-value {
  font-family: monospace;
  word-break: break-all;
  background-color: #f5f7fa;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.verify-result {
  margin-top: 10px;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background-color: #f9f9f9;
  border-radius: 4px;
  border: 1px solid #ebeef5;
}

.success-icon {
  color: #67C23A;
  font-size: 18px;
  margin-right: 8px;
}

.error-icon {
  color: #F56C6C;
  font-size: 18px;
  margin-right: 8px;
}

/* 合同状态与上链状态组合样式 */
.status-with-chain {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chain-tag {
  margin-left: 0;
  font-size: 11px;
}

/* 新增列表中显示区块链状态的样式 */
.contract-table .el-table__row .chain-status {
  margin-top: 4px;
  display: inline-block;
}

/* 修改表格内区块链标签样式 */
.el-table .chain-status .el-tag {
  height: 20px;
  padding: 0 6px;
  line-height: 18px;
  transform: scale(0.9);
  transform-origin: left;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .info-grid {
    grid-template-columns: 1fr;
  }
  
  .info-item.full-width {
    grid-column: auto;
  }
}

/* 上链进度对话框样式 */
.upload-progress-dialog {
  text-align: center;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.progress-header h3 {
  margin: 0;
  font-size: 16px;
  color: #303133;
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.step {
  width: 33.33%;
  text-align: center;
}

.step-icon {
  font-size: 24px;
  margin-bottom: 5px;
}

.step-label {
  font-size: 12px;
  color: #909399;
}

.step.active .step-icon {
  color: #409EFF;
}

.step.completed .step-icon {
  color: #67C23A;
}

.progress-bar-container {
  margin-bottom: 10px;
}

.progress-bar {
  width: 100%;
  height: 20px;
  background-color: #f0f0f0;
  border-radius: 10px;
}

.progress-fill {
  height: 100%;
  background-color: #409EFF;
  border-radius: 10px;
  transition: width 0.5s ease;
}

.success-bar {
  background-color: #67C23A;
  animation: successPulse 1.5s ease-in-out;
}

@keyframes successPulse {
  0% {
    background-color: #409EFF;
  }
  50% {
    background-color: #85ce61;
  }
  100% {
    background-color: #67C23A;
  }
}

.error-bar {
  background-color: #F56C6C;
}

.pending-bar {
  background-color: #E6A23C;
}

.progress-percentage {
  font-size: 14px;
  font-weight: bold;
  color: #303133;
}

.progress-message {
  margin-top: 10px;
  padding: 8px 12px;
  background-color: #f9f9f9;
  border-radius: 4px;
  border: 1px solid #ebeef5;
}

.success-message {
  border-color: #67C23A;
}

.error-message {
  border-color: #F56C6C;
}

.pending-message {
  border-color: #E6A23C;
}

.transaction-hash {
  margin-top: 10px;
  padding: 8px 12px;
  background-color: #f9f9f9;
  border-radius: 4px;
  border: 1px solid #ebeef5;
}

.tx-label {
  font-size: 12px;
  color: #909399;
}

.tx-value {
  font-size: 14px;
  font-weight: bold;
  color: #303133;
}

.blockchain-info {
  margin-top: 10px;
  padding: 8px 12px;
  background-color: #f9f9f9;
  border-radius: 4px;
  border: 1px solid #ebeef5;
}

.info-title {
  font-size: 16px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 10px;
}

.info-content {
  text-align: left;
}

/* 合同存证验证对话框样式 */
.verify-dialog {
  text-align: center;
}

.verify-loading {
  margin-bottom: 20px;
}

.verify-upload-container {
  padding: 24px;
  background-color: #fff;
  border-radius: 8px;
}

.upload-header {
  margin-bottom: 24px;
  text-align: center;
}

.upload-header h3 {
  margin: 0 0 16px 0;
  font-size: 20px;
  color: #409EFF;
  font-weight: bold;
}

.upload-header p {
  color: #606266;
  font-size: 14px;
  line-height: 1.6;
}

.el-upload__text {
  margin-top: 10px;
  color: #606266;
}

.el-upload__text em {
  color: #409EFF;
  font-style: normal;
  cursor: pointer;
}

.verify-result-container {
  background-color: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.verify-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #ebeef5;
}

.verify-header h3 {
  margin: 0;
  font-size: 18px;
  color: #303133;
  font-weight: bold;
}

.verify-status {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-radius: 8px;
  margin-bottom: 24px;
  transition: all 0.3s ease;
}

.verify-status.success {
  background-color: #f0f9eb;
  border: 1px solid #e1f3d8;
}

.verify-status.error {
  background-color: #fef0f0;
  border: 1px solid #fde2e2;
}

.status-icon {
  font-size: 42px;
  margin-right: 16px;
}

.verify-status.success .status-icon {
  color: #67C23A;
}

.verify-status.error .status-icon {
  color: #F56C6C;
}

.status-text h4 {
  font-size: 18px;
  margin: 0 0 8px 0;
  color: #303133;
}

.verify-status.success .status-text h4 {
  color: #67C23A;
}

.verify-status.error .status-text h4 {
  color: #F56C6C;
}

.status-text p {
  margin: 0;
  color: #606266;
  font-size: 14px;
  line-height: 1.5;
}

.detail-section {
  margin-bottom: 24px;
  background-color: #f8f9fb;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.section-title {
  font-size: 16px;
  color: #409EFF;
  font-weight: bold;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px dashed #ebeef5;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.detail-item {
  padding: 12px;
  background-color: #fff;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.detail-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.detail-label {
  font-size: 14px;
  color: #909399;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
}

.detail-label i {
  margin-right: 6px;
  color: #409EFF;
}

.tx-hash {
  font-family: monospace;
  font-size: 12px;
  background-color: #f5f7fa;
  padding: 6px 8px;
  border-radius: 4px;
}

.hash-comparison {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  margin-bottom: 16px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.hash-match {
  background-color: #f0f9eb;
  border: 1px solid #e1f3d8;
}

.hash-mismatch {
  background-color: #fef0f0;
  border: 1px solid #fde2e2;
}

.hash-icon {
  font-size: 24px;
  margin-right: 12px;
}

.hash-match .hash-icon {
  color: #67C23A;
}

.hash-mismatch .hash-icon {
  color: #F56C6C;
}

.hash-text {
  font-size: 16px;
  font-weight: bold;
}

.hash-match .hash-text {
  color: #67C23A;
}

.hash-mismatch .hash-text {
  color: #F56C6C;
}

.hash-details {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.hash-item {
  background-color: #fff;
  border-radius: 6px;
  padding: 12px;
  transition: all 0.3s ease;
}

.hash-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.hash-label {
  font-size: 14px;
  color: #909399;
  margin-bottom: 8px;
}

.hash-value {
  font-family: monospace;
  font-size: 13px;
  background-color: #f5f7fa;
  padding: 10px;
  border-radius: 4px;
  word-break: break-all;
  overflow-wrap: break-word;
}

.verify-info {
  background-color: #ecf5ff;
  border-radius: 8px;
  padding: 16px;
  margin-top: 20px;
  margin-bottom: 16px;
  border: 1px solid #d9ecff;
  transition: all 0.3s ease;
}

.verify-info:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transform: translateY(-2px);
}

.info-title {
  font-size: 16px;
  color: #409EFF;
  font-weight: bold;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
}

.info-title i {
  margin-right: 8px;
  font-size: 18px;
}

.info-content {
  color: #606266;
  font-size: 14px;
  line-height: 1.6;
}

.info-content p {
  margin: 8px 0;
}

.verify-dialog {
  border-radius: 8px;
  overflow: hidden;
}

.verify-dialog .el-dialog__header {
  background-color: #409EFF;
  color: white;
  padding: 16px 20px;
}

.verify-dialog .el-dialog__title {
  color: white;
  font-weight: bold;
}

.verify-dialog .el-dialog__headerbtn .el-dialog__close {
  color: white;
}

.verify-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
}

.verify-loading i {
  font-size: 48px;
  color: #409EFF;
  margin-bottom: 20px;
  animation: rotate 1.5s linear infinite;
}

.verify-loading p {
  color: #606266;
  font-size: 16px;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.upload-form {
  margin: 20px 0;
  padding: 20px;
  background-color: #f8f9fb;
  border-radius: 8px;
}

.contract-file-uploader {
  border: 2px dashed #d9d9d9;
  border-radius: 6px;
  padding: 20px;
  text-align: center;
  transition: all 0.3s;
  background-color: #fff;
}

.contract-file-uploader:hover {
  border-color: #409EFF;
}

.el-upload__tip {
  margin-top: 12px;
  color: #909399;
}

.dialog-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.verify-flat-container {
  background-color: #fff;
  border-radius: 4px;
  margin-bottom: 10px;
}

.verify-flat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  margin-bottom: 15px;
  border-bottom: 1px solid #ebeef5;
}

.flat-header-left {
  display: flex;
  align-items: center;
}

.contract-title {
  font-size: 16px;
  font-weight: 500;
  color: #303133;
  margin-right: 10px;
}

.verify-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 15px;
  font-size: 13px;
}

.verify-badge.success {
  background-color: #f0f9eb;
  color: #67C23A;
}

.verify-badge.error {
  background-color: #fef0f0;
  color: #F56C6C;
}

.verify-badge i {
  margin-right: 4px;
  font-size: 14px;
}

.verify-row {
  margin-bottom: 15px;
}

.verify-panel {
  height: 100%;
  border-radius: 4px;
  border: 1px solid #ebeef5;
  background-color: #fff;
  overflow: hidden;
  transition: all 0.2s ease;
}

.verify-panel:hover {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.panel-header {
  padding: 10px 15px;
  font-size: 14px;
  background-color: #f5f7fa;
  color: #303133;
  font-weight: 500;
  border-bottom: 1px solid #ebeef5;
}

.panel-header i {
  color: #409EFF;
  margin-right: 5px;
}

.panel-body {
  padding: 12px 15px;
}

.verify-result-text {
  font-size: 14px;
  line-height: 1.5;
}

.success-text {
  color: #67C23A;
}

.error-text {
  color: #F56C6C;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}

.info-item:last-child {
  margin-bottom: 0;
}

.item-label {
  color: #909399;
}

.item-value {
  color: #303133;
  font-weight: 500;
}

.tx-id {
  font-family: monospace;
  color: #409EFF;
  cursor: pointer;
}

.hash-comparison-mini {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 10px;
}

.hash-comparison-mini.success {
  background-color: #f0f9eb;
}

.hash-comparison-mini.error {
  background-color: #fef0f0;
}

.hash-comparison-mini i {
  margin-right: 8px;
  font-size: 16px;
}

.hash-comparison-mini.success i {
  color: #67C23A;
}

.hash-comparison-mini.error i {
  color: #F56C6C;
}

.hash-popup {
  padding: 10px;
}

.hash-item {
  margin-bottom: 10px;
}

.hash-label {
  font-size: 13px;
  color: #909399;
  margin-bottom: 5px;
}

.hash-value.mono {
  font-family: monospace;
  font-size: 12px;
  background-color: #f5f7fa;
  padding: 8px;
  border-radius: 4px;
  overflow-wrap: break-word;
  word-break: break-all;
}

.verify-flat-footer {
  padding: 10px 0;
  border-top: 1px dashed #ebeef5;
  font-size: 12px;
  color: #909399;
  text-align: center;
}

/* 合同上传对话框样式 */
.contract-upload-dialog {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.contract-upload-dialog .el-dialog__header {
  background: linear-gradient(135deg, #409EFF 0%, #66b1ff 100%);
  color: white;
  padding: 20px 24px;
  border-bottom: none;
}

.contract-upload-dialog .el-dialog__title {
  color: white;
  font-weight: 600;
  font-size: 18px;
}

.contract-upload-dialog .el-dialog__headerbtn .el-dialog__close {
  color: white;
  font-size: 18px;
  top: 20px;
}

.contract-upload-dialog .el-dialog__headerbtn:hover .el-dialog__close {
  color: #f0f0f0;
  transform: rotate(90deg);
  transition: all 0.3s ease;
}

.dialog-content {
  padding: 24px;
  background-color: #fff;
}

.replace-form {
  margin-top: 10px;
}

.contract-info {
  background-color: #f8f9fb;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #ebeef5;
  transition: all 0.3s ease;
}

.contract-info:hover {
  border-color: #c6e2ff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.contract-label {
  color: #909399;
  font-size: 14px;
  margin-right: 8px;
}

.contract-value {
  color: #303133;
  font-weight: 500;
  font-size: 14px;
}

.contract-file-uploader {
  border: 2px dashed #dcdfe6;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  transition: all 0.3s ease;
  background-color: #fff;
}

.contract-file-uploader:hover {
  border-color: #409EFF;
  background-color: #f8f9fb;
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-content i {
  font-size: 48px;
  color: #409EFF;
  margin-bottom: 16px;
}

.upload-text {
  margin-bottom: 12px;
}

.primary-text {
  color: #606266;
  font-size: 14px;
}

.secondary-text {
  color: #409EFF;
  font-size: 14px;
  margin-left: 4px;
  cursor: pointer;
}

.upload-tip {
  color: #909399;
  font-size: 12px;
  margin-top: 8px;
}

.contract-upload-dialog .dialog-footer {
  padding: 16px 24px;
  border-top: 1px solid #ebeef5;
  background-color: #f8f9fb;
  text-align: right;
}

.contract-upload-dialog .el-button {
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 6px;
  transition: all 0.3s ease;
  margin-left: 12px;
}

.contract-upload-dialog .el-button--primary {
  background: linear-gradient(135deg, #409EFF 0%, #66b1ff 100%);
  border: none;
}

.contract-upload-dialog .el-button--primary:hover {
  background: linear-gradient(135deg, #66b1ff 0%, #409EFF 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
}

.contract-upload-dialog .el-button--default {
  background-color: #fff;
  border-color: #dcdfe6;
  color: #606266;
}

.contract-upload-dialog .el-button--default:hover {
  color: #409EFF;
  border-color: #c6e2ff;
  background-color: #ecf5ff;
  transform: translateY(-1px);
}

/* 文件上传列表样式优化 */
.contract-file-uploader .el-upload-list {
  margin-top: 16px;
}

.contract-file-uploader .el-upload-list__item {
  transition: all 0.3s ease;
  border-radius: 4px;
}

.contract-file-uploader .el-upload-list__item:hover {
  background-color: #f8f9fb;
}

.contract-file-uploader .el-upload-list__item-name {
  color: #606266;
}

.contract-file-uploader .el-upload-list__item-status-label {
  color: #67C23A;
}

/* 加载状态样式 */
.contract-upload-dialog .el-button.is-loading {
  background: linear-gradient(135deg, #409EFF 0%, #66b1ff 100%);
  opacity: 0.8;
}

.contract-upload-dialog .el-button.is-loading::before {
  background-color: rgba(255, 255, 255, 0.35);
}

/* 合同替换对话框样式 */
.contract-replace-dialog {
  border-radius: 16px;
  overflow: hidden;
}

.contract-replace-dialog .el-dialog__header {
  padding: 0;
  margin: 0;
}

.contract-replace-dialog .el-dialog__headerbtn {
  top: 20px;
  right: 20px;
  z-index: 1;
}

.contract-replace-dialog .el-dialog__headerbtn .el-dialog__close {
  color: #606266;
  font-size: 18px;
  transition: all 0.3s ease;
}

.contract-replace-dialog .el-dialog__headerbtn:hover .el-dialog__close {
  color: #409EFF;
  transform: rotate(90deg);
}

.contract-replace-dialog .el-dialog__body {
  padding: 0;
}

.replace-dialog-content {
  padding: 24px;
}

/* 合同信息卡片样式 */
.contract-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  margin-bottom: 24px;
  overflow: hidden;
}

.contract-header {
  background: #f8f9fb;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebeef5;
}

.contract-header i {
  font-size: 20px;
  color: #409EFF;
  margin-right: 8px;
}

.contract-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.contract-body {
  padding: 20px;
}

.contract-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: #f8f9fb;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.contract-item:hover {
  background: #ecf5ff;
}

.item-label {
  color: #909399;
  font-size: 14px;
  margin-right: 12px;
}

.item-value {
  color: #303133;
  font-size: 14px;
  font-weight: 500;
}

/* 文件上传区域样式 */
.upload-section {
  margin-bottom: 24px;
}

.file-uploader {
  width: 100%;
}

.file-uploader .el-upload {
  width: 100%;
}

.file-uploader .el-upload-dragger {
  width: 100%;
  height: 200px;
  border: 2px dashed #dcdfe6;
  border-radius: 12px;
  background: #fff;
  transition: all 0.3s ease;
}

.file-uploader .el-upload-dragger:hover {
  border-color: #409EFF;
  background: #f8f9fb;
}

.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}

.upload-icon {
  width: 64px;
  height: 64px;
  background: #ecf5ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  transition: all 0.3s ease;
}

.upload-icon i {
  font-size: 32px;
  color: #409EFF;
}

.file-uploader:hover .upload-icon {
  transform: scale(1.1);
  background: #409EFF;
}

.file-uploader:hover .upload-icon i {
  color: #fff;
}

.upload-text {
  text-align: center;
}

.main-text {
  font-size: 16px;
  color: #303133;
  margin-bottom: 8px;
}

.sub-text {
  font-size: 14px;
  color: #909399;
}

/* 上传提示样式 */
.upload-tips {
  background: #f8f9fb;
  border-radius: 12px;
  padding: 16px 20px;
}

.tip-item {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.tip-item:last-child {
  margin-bottom: 0;
}

.tip-item i {
  font-size: 16px;
  margin-right: 8px;
}

.tip-item:first-child i {
  color: #409EFF;
}

.tip-item:last-child i {
  color: #E6A23C;
}

.tip-item span {
  font-size: 14px;
  color: #606266;
}

/* 底部按钮样式 */
.dialog-footer {
  padding: 16px 24px;
  background: #f8f9fb;
  border-top: 1px solid #ebeef5;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.cancel-btn {
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid #dcdfe6;
  background: #fff;
  color: #606266;
  transition: all 0.3s ease;
}

.cancel-btn:hover {
  color: #409EFF;
  border-color: #c6e2ff;
  background: #ecf5ff;
}

.confirm-btn {
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 8px;
  background: #409EFF;
  border: none;
  color: #fff;
  transition: all 0.3s ease;
}

.confirm-btn:hover {
  background: #66b1ff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
}

.confirm-btn.is-loading {
  background: #409EFF;
  opacity: 0.8;
}

/* 文件列表样式 */
.file-uploader .el-upload-list {
  margin-top: 16px;
}

.file-uploader .el-upload-list__item {
  padding: 8px 12px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.file-uploader .el-upload-list__item:hover {
  background: #f8f9fb;
}

.file-uploader .el-upload-list__item-name {
  color: #606266;
}

.file-uploader .el-upload-list__item-status-label {
  color: #67C23A;
}
</style>
